import React, {useEffect} from 'react';
import {connect} from 'react-redux';
import {Pagination} from 'antd';
import {confirmrefund} from '../../api';
import action from '../../store/actions/refund';
import Header from './Header';
import RefundList from './RefundList';


function Refund(props) {

  useEffect(() => {
    props.GET_REFUND_LIST();
  }, []);

  // 确认退款
  const tempConfirmRefund = async refund_no => {
    await confirmrefund(refund_no);
    await props.GET_REFUND_LIST(props.current);
  };

  // 分页改变
  const pageChange = page => {
    props.GET_REFUND_LIST(page);
  };
  return (
    <div className={'Refund'}>
      <Header/>
      <RefundList refundList={props.refundList} tempConfirmRefund={tempConfirmRefund}/>
      <Pagination
        current={props.current}
        onChange={pageChange}
        total={props.pageCount ? props.pageCount : 1}
        style={{textAlign: 'center', marginTop: '20px'}}
        pageSize={10}
        hideOnSinglePage
      />
    </div>
  );
}

const mapStateToProps = state => state.refund;
export default connect(mapStateToProps, action)(Refund);
